package com.zhuoxu.gktf.base

import android.app.Dialog
import androidx.fragment.app.Fragment
import androidx.lifecycle.lifecycleScope
import kotlinx.coroutines.*
import kotlin.coroutines.EmptyCoroutineContext

open class BaseFragment: Fragment() {

    // 防止内存泄露，自定义管理Dialog销毁
    val listDialog= mutableListOf<Dialog>()

    fun showDialog(dialog: Dialog){
        if(!listDialog.contains(dialog)){
            listDialog.add(dialog)
        }
        if(!dialog.isShowing){
            dialog.show()
        }
    }

    fun dismisDialog(dialog: Dialog){
        if(listDialog.contains(dialog)){
            listDialog.remove(dialog)
        }
        if(dialog.isShowing){
            dialog.dismiss()
        }
    }


    override fun onDestroy() {
        if(listDialog.size>0){
            for (dialog in listDialog){
                dialog.dismiss()
            }
            listDialog.clear()
        }
        super.onDestroy()
    }





}